﻿// (c)2010 David Schwarz (david.schwarz@live.com)
// This file is licensed under GNU GPL v2 license, see more at http://www.gnu.org/licenses/gpl-2.0.html
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Timers;
using System;
using Microsoft.Xna.Framework.Audio;
namespace Z2.Core
{

	#region Using

	#endregion

	/// <summary>
	/// Bedna :)
	/// </summary>
	public class Crate : ObjectBase
	{

		#region Const

		private const string GRAPHICS = "crate";

		#endregion

		private SoundEffect m_smash;
		private static ParticleSettings _particleSettings;

		#region Constructor

		static Crate()
		{
			_particleSettings = new ParticleSettings();
			_particleSettings.Ammount = 5;
		}

		/// <summary>
		/// Konstruktor
		/// </summary>
		public Crate()
			: base(SpriteManager.Instance.LoadSprite(Crate.GRAPHICS, 1, 1, "crates"))
		{
			this.MaxHorizontalSpeed = 6.0f;
			this.Behavior = new GravityBehavior();
			this.m_smash = SoundManager.Instance.LoadSound("crate_smash");
		}

		#endregion

		public override void Initialize()
		{
			base.Initialize();
			this.Sprite.CreateSlices(1, 4);
		}

		internal override bool CantCollide(ObjectBase obj)
		{
			return obj is ItemBase;
		}

		internal override void OnVerticalCollision(IntersectionResult result)
		{
			base.OnVerticalCollision(result);
			if (this.Move.Y > 8)
			{
				// SoundManager.Instance.PlayDistance(this.m_smash, this);
				Vector2 position = this.Position;
				ParticleEngine.Instance.Slice(this, new Vector2(5, 0));
				//ParticleEngine.Instance.CreateItems(position, ItemType.Strawberry, _particleSettings);
				Strawberry berry = new Strawberry();
				Strawberry berry1 = new Strawberry();
				Strawberry berry2 = new Strawberry();
				position.Y += (Sprite.FrameHeight - berry.Sprite.FrameHeight);
				berry.Position = position;
				position.X += berry.Sprite.FrameWidth;
				berry1.Position = position;
				position.X += berry.Sprite.FrameWidth;
				berry2.Position = position;
				World.Current.RegisterObject(berry);
				World.Current.RegisterObject(berry1);
				World.Current.RegisterObject(berry2);
				berry.ChangeVertical(-50);
				berry1.ChangeVertical(-60);
				berry2.ChangeVertical(-40);
			}
		}
	
	}
}
